﻿// ===============================================================================
// XCI.WinForm.Platform 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System.Collections;
using System.Collections.Generic;

namespace XCI.Core
{
    /// <summary>
    /// 分页列表
    /// </summary>
    public interface IPagingList
    {
        /// <summary>
        /// 页码索引,从1开始
        /// </summary>
        int GetPageIndex();

        /// <summary>
        /// 每页记录数
        /// </summary>
        int GetPageSize();

        /// <summary>
        /// 总记录数
        /// </summary>
        int GetTotal();

        /// <summary>
        /// 获取数据集合
        /// </summary>
        IList GetRows();
    }

    /// <summary>
    /// 分页列表
    /// </summary>
    public class PagingList<T> : IPagingList
    {
        /// <summary>
        /// 页码索引,从1开始
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页记录数
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 数据集合
        /// </summary>
        public List<T> Rows { get; set; }

        /// <summary>
        /// 页码索引,从1开始
        /// </summary>
        public int GetPageIndex()
        {
            return PageIndex;
        }

        /// <summary>
        /// 每页记录数
        /// </summary>
        public int GetPageSize()
        {
            return PageSize;
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int GetTotal()
        {
            return Total;
        }

        /// <summary>
        /// 获取数据集合
        /// </summary>
        public IList GetRows()
        {
            return Rows;
        }

        public PagingList()
        {

        }

        public PagingList(List<T> rows)
        {
            PageIndex = 1;
            PageSize = 0;
            if (rows == null)
            {
                Rows = new List<T>();
                Total = 0;
            }
            else
            {
                Rows = rows;
                Total = rows.Count;
            }
        }
    }
}